<template>
	<view>
		<page-head :transparent='false'>
			<slot slot="title">{{title.length>10?title.substr(0,10)+'...':title}}</slot>
		</page-head>
		<nine-goods-list :goodsList="goodsList" :loadingText="loadingText" @eventClick="toNineDetail"></nine-goods-list>
	</view>
</template>

<script>
	import NineGoodsList from '../../components/nine-goods-list.vue';

	let page = 1,
		pagesize = 20;
	export default {
		components: {
			NineGoodsList
		},
		onShow() {
			genCommonData();
		},
		onLoad(event) {
			page = 1;
			this.genNineGoodsList();
			this.ti = '9.9包邮';
		},
		onReachBottom() {
			this.genNineGoodsList();
		},
		data() {
			return {
				goodsList: [],
				loadingText: '加载中...',
				title: '9.9包邮'
			};
		},
		methods: {
			async genNineGoodsList() {
				try {
					let data = {
						page: page,
						pagesize: pagesize
					};
					let res = await this.$request.post('/coupon-product/myq/tbGoods/9.9FreeShipping', {
						data: data
					});
					let datas = res.data;
					let newList = datas.data;
					if (newList != '' && newList.length > 0) {
						this.goodsList = this.goodsList.concat(newList);
						page++;
						if (page == 500 || newList.length < 20) {
							this.loadingText = '没有更多了';
						}
					} else {
						this.loadingText = '没有更多了';
					}
				} catch (e) {
					console.log(e);
					this.loadingText = '没有更多了';
				}
			},
			toNineDetail(e) {
				Date.prototype.toLocaleString = function() {
					return this.getFullYear() + '/' + (this.getMonth() + 1) + '/' + this.getDate();
				};
				let startTime = new Date(parseInt(e.online_start_time) * 1000).toLocaleString().substr(0, 9);
				let endTime = new Date(parseInt(e.online_end_time) * 1000).toLocaleString().substr(0, 9);
				h5NavigateTo({
					url: '../tbdetail/tbdetail?skuId=' +
						e.num_iid +
						'&cid=0' +
						'&title=1' +
						'&seller=淘宝' +
						'&coupon_amount=' +
						e.youhuiquan +
						'&startTime=' +
						startTime +
						'&endTime=' +
						endTime +
						'&tm=false'
				});
			},
			setTitle(title) {
				this.title = title
			}
		}
	};
</script>

<style></style>
